<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model backend\models\adv\Adv */

$this->title = '修改密码';
$this->params['breadcrumbs'][] = $this->title;
?>
<p></p>
<div class="update-password">

    <div class="adv-form">

        <?php $form = ActiveForm::begin([
            'options' => [
                'class' => 'form-horizontal',
                'onkeydown' => "if(event.keyCode==13)return false;",
            ],
            'action' => 'update-password',
            'id' => 'update-password-form',
        ]); ?>

        <div class="panel panel-default">
            <div class="panel-body">

                <div class="row">
                    <label class="col-sm-2 control-label"><span class="red">*</span>旧密码</label>
                    <div class="col-xs-9 col-sm-3">
                        <?= $form->field($model, 'password')->textInput(['value' => '','maxlength' => true, 'placeholder' => '旧密码'])->label(false) ?>
                    </div>
                </div>

                <div class="row">
                    <label class="col-sm-2 control-label"><span class="red">*</span>新密码</label>
                    <div class="col-xs-9 col-sm-3">
                        <?= $form->field($model, 'new_password')->textInput(['maxlength' => true, 'placeholder' => '新密码'])->label(false) ?>
                    </div>
                    <div class="col-xs-9 col-sm-3">
                        <div class="hint-block"><i class="glyphicon glyphicon-warning-sign red"></i> 密码至少6个字符</div>
                    </div>
                </div>

            </div>
        </div>

        <div class="row">
            <div class="col-sm-offset-2 col-sm-10">
                <div class="form-group">
                    <?= Html::submitButton('保 存', ['class' => 'btn btn-success btn-lg']) ?>
                </div>
            </div>
        </div>

        <?php ActiveForm::end(); ?>

    </div>

</div>

<script language="JavaScript">
    <?php $this->beginBlock(Yii::$app->controller->route) ?>

    jQuery(document).ready(function () {
        highlight_subnav('index/index'); //子导航高亮

        //此处点击按钮提交数据的jquery
        $(document).on('beforeSubmit', 'form#update-password-form', function () {
            var form = $(this);
            //返回错误的表单信息
            if (form.find('.has-error').length)
            {
                return false;
            }
            //表单提交
            $.ajax({
                url: form.attr('action'),
                type: 'post',
                dataType: "json",
                data: form.serialize(),
                success: function (r){
                    if(r.status == 1){
                        layer.msg(r.msg);
                    }else {
                        layer.alert(r.msg,{'title':'提示','icon':7});
                    }
                },
                error: function (){
                    layer.alert('系统错误',{'title':'提示','icon':7});
                    return false;
                }
            });
            return false;
        });
    });

    <?php
    $this->endBlock();
    $this->registerJs($this->blocks[Yii::$app->controller->route], \yii\web\View::POS_END);
    ?>
</script>
